package com.yanqu.road.server.cmd.cookboy.process2;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.cookboy.CookBoyProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.activity.cookboy.CookBoyActivityMgr;
import com.yanqu.road.server.manger.activity.cookboy.CookBoyMgr;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;

/**
 * @Author : Cxp
 * @Time : 2024-11-28
 * @Description : 设置自动回访的汤勺
 */

@Cmd(code = Protocol.S_COOK_BOY2_SET_AUTO_JOIN_SPOON, desc = "设置自动回访的汤勺")
public class CookBoy2SetAutoJoinSpoonCmd extends AbstractCommand {
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        CookBoyProto.CookBoy2SetAutoJoinSpoonReqMsg reqMsg =
                CookBoyProto.CookBoy2SetAutoJoinSpoonReqMsg.parseFrom(packet.getBytes());
        int activityId = reqMsg.getActivityId();
        ActivityInfo activityInfo = CookBoyActivityMgr.getOpenActivityInfo(activityId);
        if (activityInfo == null) {
            ret = GameErrorCode.E_ACTIVITY_NO_FOUND;
            return;
        }
        if (player.getUserId() != reqMsg.getUserId()) {
            ret = GameErrorCode.E_USER_NO_FOUND;
            return;
        }
        ret = CookBoyMgr.setAutoJoinSpoon(activityId, player.getUserId(), reqMsg.getSpoonList());
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0) {
            CookBoyProto.CookBoy2SetAutoJoinSpoonRespMsg.Builder respMsg =
                    CookBoyProto.CookBoy2SetAutoJoinSpoonRespMsg.newBuilder();
            respMsg.setRet(ret);
            player.sendPacket(Protocol.U_COOK_BOY2_SET_AUTO_JOIN_SPOON, respMsg);
        }
    }
}
